// 配置服务器相关信息
let express = require('express')
let app = express()
let cors = require('cors')
let bodyParser = require('body-parser')
let article_router = require('./router/article_router')
let auother_router = require('./router/auother_router')
let flow_router = require('./router/flow_router')
let category_router = require('./router/category_router')
let commnet_router = require('./router/commnet_router')
let user_router = require('./router/user_router')

app.use(bodyParser.json()); //配置解析，用于解析json和urlencoded格式的数据
app.use(bodyParser.urlencoded({
	extended: false
}));

app.use(cors()) //配置跨域
app.use(article_router) //配置文章列表路由
app.use(auother_router) //配置作者列表路由
app.use(flow_router) //配置文章流量列表路由
app.use(category_router) //配置文章分类列表路由
app.use(commnet_router) //配置文章评论列表路由
app.use(user_router) //配置用户登录路由

var  {jwtAuth} = require("./api/token");
app.use(jwtAuth);
//当token失效返回提示信息
app.use(function (err, req, res, next) {
	if (err.status == 401) {
		return res.status(401).send('token失效');
	}
});
app.listen(80, () => {
	console.log('服务器启动成功');
})
module.exports;